package cn.net.mugui.net.pc.task;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

import cn.net.mugui.net.pc.bean.TMBiliBaseBean;


/**
 * @ClassName HttpRoomData
 * @Description TODO
 * @author BanqiJane
 * @date 2020年8月10日 下午12:28:59
 *
 * @Copyright:2020 blogs.acproject.xyz Inc. All rights reserved.
 */
public class HttpRoomData {

	/**
	 * 获取连接目标房间websocket端口 接口
	 * @return 
	 *
	 * @return
	 */
	public static RoomDataBean httpGetConf(Integer room_id) {
		String data = null;
		JSONObject jsonObject = null;
		short code = -1;
		Map<String, String> headers = null;
		Map<String, String> datas = null;
		headers = new HashMap<>(3);
		headers.put("referer", "https://live.bilibili.com/" +room_id);
		headers.put("user-agent",
				"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");
//		if (!StringUtils.isEmpty(PublicDataConf.USERCOOKIE)) {
//			headers.put("cookie", PublicDataConf.USERCOOKIE);
//		}
		datas = new HashMap<>(3);
		datas.put("id", room_id+"");
		datas.put("type", "0");
		try {
			data = OkHttp3Utils.getHttp3Utils()
					.httpGet("https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo", headers, datas)
					.body().string();
		} catch (Exception e) {
			data = null;
		}
		jsonObject = JSONObject.parseObject(data);
		TMBiliBaseBean tmBiliBaseBean=TMBiliBaseBean.newBean(TMBiliBaseBean.class,jsonObject);
		JSONObject data2 = tmBiliBaseBean.getData();
		RoomDataBean newBean = RoomDataBean.newBean(RoomDataBean.class, data2);
		return newBean;
	}

}
